package com.xxwu.springblogsystem.mapper;

import com.xxwu.springblogsystem.model.Blog;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface BlogMapper {
    //根据博客id查询博客信息
    @Select("select * from blog where id = #{id} and delete_flag = 0")
    Blog selectById(Integer id);

    //查询博客列表
    @Select("select * from blog where delete_flag = 0")
    List<Blog> selectAll();

    //新增博客信息
    @Insert("insert into blog(title, content, user_id) values(#{title}, #{content}, #{userId})")
    Integer insert(Blog blog);

    //修改博客信息
    Integer update(Blog blog);

    //删除博客
    @Delete("update blog set delete_flag = 1 where id = #{id}")
    Integer delete(Integer id);
}
